package com.yh.homestay.controller;

import com.yh.homestay.aop.SystemLog;
import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.pojo.UserMember;
import com.yh.homestay.service.UserMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName UserMemberController
 * @Description 用户Controller
 * @Date 2020/1/10 9:55
 */
@RestController
@Api(description = "用户管理")
@RequestMapping(value = "/user")
public class UserMemberController {
    @Autowired
    private UserMemberService userService;

    /**
     * @param page
     * @param limit
     * @param userName
     * @Date: 2020/1/14 17:49
     * @Description: 获取用户列表
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @SystemLog(methods = "用户列表", module = "用户管理")
    @ApiOperation(value = "获取用户列表", notes = "获取用户列表信息或者模糊查询数据")
    public HomeStayResult selectAll(Integer page, Integer limit, String userName) {
        return userService.showUserMember(page, limit, userName);
    }

    /**
     * @param userMember
     * @Date: 2020/1/14 17:49
     * @Description: 添加用户
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @SystemLog(methods = "添加用户", module = "用户管理")
    @ApiOperation(value = "添加用户", notes = "添加用户信息")
    public HomeStayResult addUser(UserMember userMember) {
        return userService.insertUserMember(userMember);
    }

    /**
     * @param id
     * @Date: 2020/1/14 17:49
     * @Description: 回显用户信息
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/one/{id}", method = RequestMethod.POST)
    @SystemLog(methods = "修改用户信息", module = "用户管理")
    @ApiOperation(value = "回显用户信息", notes = "根据id回显用户信息")
    public HomeStayResult editMember(@PathVariable("id") Integer id) {
        return userService.showOneUserMember(id);
    }

    /**
     * @param userMember
     * @Date: 2020/1/14 17:49
     * @Description: 修改用户信息
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @SystemLog(methods = "修改用户信息", module = "用户管理")
    @ApiOperation(value = "修改用户信息", notes = "修改用户信息")
    public HomeStayResult updateUser(UserMember userMember) {
        return userService.updateUserMember(userMember);
    }

    /**
     * @param userId
     * @Date: 2020/1/14 17:49
     * @Description: 删除用户
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @SystemLog(methods = "删除用户", module = "用户管理")
    @ApiOperation(value = "删除用户", notes = "根据id删除用户")
    public HomeStayResult deleteById(Integer userId) {
        return userService.deleteUserMember(userId);
    }

    /**
     * @param ids
     * @Date: 2020/1/14 17:49
     * @Description: 批量删除用户
     * @return: com.yh.homestay.common.HomeStayResult
     */
    @RequestMapping(value = "/deleteBatch", method = RequestMethod.POST)
    @SystemLog(methods = "删除多个用户", module = "用户管理")
    @ApiOperation(value = "批量删除用户", notes = "根据id批量删除用户")
    public HomeStayResult delete(@RequestParam("ids") List<Integer> ids) {
        return userService.deleteBatchUsers(ids);
    }

}



